package com.zr.dao.impl;
import java.util.List;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import com.zr.dao.SelectOrdersDao;
import com.zr.model.Car;
import com.zr.model.Orders;
@Repository("selectOrdersDao")
public class SelectOrdersDaoImpl<T> extends BaseDaOImpl<T>implements SelectOrdersDao{

	@Override
	public long findOrdersCount() {
		String hql = "select count(*) from Orders where orderstatus='已处理' OR orderstatus='运输中' ";
		List<Object>  obj = this.getCurrentSession().createQuery(hql).list();
		return (long) obj.get(0);
	}

	@Override
	public List<Orders> findOrdersMsg(int page, int rows) {		
		String hql = "from Orders where orderstatus='已处理' OR orderstatus='运输中'";
		Query  query  =  this.getCurrentSession().createQuery(hql);
		query.setFirstResult((page-1)*rows);
		query.setMaxResults(rows);
		List<Orders> orders =  query.list();
		return orders;
	}

	@Override
	public long findCarsCount() {
		String hql = "select count(*) from Car where state='运营'OR state='空闲'";
		List<Object>  obj = this.getCurrentSession().createQuery(hql).list();
		return (long) obj.get(0);
	}

	@Override
	public List<Car> findCars(int page, int rows) {		
		String hql = "from Car where state='运营'OR state='空闲'";
		Query  query  =  this.getCurrentSession().createQuery(hql);
		query.setFirstResult((page-1)*rows);
		query.setMaxResults(rows);
		List<Car> car =  query.list();
		return car;
	}

}
